﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Perceiveit.Xml
{
    /// <summary>
    /// Provides a root class for storing a collection of XEntity's.
    /// NOTE: you should not inherit directly from this class unless you want to
    /// implement your own collection, but use the provided XEntityCollection&lt;T&gt; class
    /// or XEntityKeyedCollection&lt;T&gt; class.
    /// </summary>
    public abstract class XEntityCollectionBase : XEntity
    {

        private int _changeIncrement = 0;

        /// <summary>
        /// Used for managing change increments that 
        /// enumerators record when they start
        /// </summary>
        /// <returns>The change increment</returns>
        protected int GetChangeIncrement()
        {
            return _changeIncrement;
        }

        /// <summary>
        /// Increments the ChangeIncrement value to register that this collection is no longer
        /// the same. Existing enumerators will become invalidated after a call to this method.
        /// </summary>
        protected virtual void RegisterCollectionChanged()
        {
            _changeIncrement++;
        }

        /// <summary>
        /// Overrides the default method to register a collection change.
        /// </summary>
        protected override void OnInitComplete()
        {
            base.OnInitComplete();
            this.RegisterCollectionChanged();
        }
        
    }
}
